<?php 
set_time_limit(0) ;
if(session_start()) ; //echo "session started";
error_reporting(E_ALL);
include('./paginator/ajaxpaginator.class.php');
require ("dbconf.php");
$mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbname);


$query = "SELECT * FROM files";

$recordsPerPage = 50;  //TODO PARAMETRIZE
 
 
 $searchQuery = !empty($_GET['search'])?$searchQuery = $_GET['search']:''; 
$pageId= empty($_GET['page'])? 1:$mysqli->real_escape_string($_GET['page']); 

 

$paginator = new AjaxPaginator($pageId,$recordsPerPage,$query,$mysqli);


$paginator->searchQuery = $searchQuery;

//$paginator->debug = true;
try{
	$rows = $paginator->paginate();
}catch (Exception $e){
	echo $e->getMessage();
}
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="jquery.easing.1.3.js" type="text/javascript"></script>
	<script src="./jqueryFileTree/jqueryFileTree.js" type="text/javascript"></script>
	<script src="./jquery-ui-1.8.1.custom/js/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script>
	<link type="text/css" href="./jquery-ui-1.8.1.custom/css/smoothness/jquery-ui-1.8.1.custom.css"  rel="Stylesheet" />	
	<link type="text/css" href="./jquery-ui-1.8.1.custom/css/smoothness/jquery-ui-1.8.1.custom.css"  rel="Stylesheet" />	

	<script type="text/javascript" src="./paginator/js/jquery.paginate.js"></script>
	
	<link href="./jqueryFileTree/jqueryFileTree.css" rel="stylesheet" type="text/css" media="screen" />
	<link href="./style/main.css" rel="stylesheet" type="text/css" media="screen" />
 	
	<script type="text/javascript">
	$(document).ready (function () {
		$('#srch_btn').click(function () {
			$('#listing_container').Paginate();
			return false;	
		});
		
		$('.paginator a').click(function () {
			$('#listing_container').Paginate(this.id);
			return false;	
		});


	});
	</script>	
	
	
	</head>
	<body>

		<h1>Lander</h1>
		<h4 style="color:#dd4444;">lookin another directory erelong</h4>
		<!--div id="div00001" style="width:500px;height:600px;background-color:#eee;">aaa</div-->
		

			<div id="communication_console" class="lander_maincss">
			<!--Comunicazioni-->
			</div>

			
			
			
			
			
			
					
					
		<div id="wrapper">
		<div id='search-box' class="search-box">
		<form action="" method="get">
		<input id="search" type="text" class="search" />
		<?php 
		$getArray = array();
		parse_str($_SERVER['QUERY_STRING'],$getArray);

		foreach($getArray as $key=>$value){

			echo "<input type='hidden' name='{$key}' id='{$key}' value='{$value}' />";
		}
		?>
		<input id="srch_btn" type="submit" value="search" class="button" />
		</form>
		</div>
		<br class="clear" />
		<div id="listing_container">



			<table border="0" cellpadding="2" cellspacing="0" class="listing">
			<tr>
				<th nowrap="nowrap" width="40"> ID</th>
				<th nowrap="nowrap" width="450" align='left'>Name</th>
			</tr>
		<?php

		foreach($rows as $row){
			echo "<tr>";
			echo "<td nowrap='nowrap' align='center'>{$row['directory_id']}</td>";
			echo "<td nowrap='nowrap' align='left'>{$row['name']}</td>";
			echo "<td nowrap='nowrap' align='center'>{$row['extension']}</td>";			
			echo "<td nowrap='nowrap' align='center'>{$row['stamp_creation']}</td>";
			echo "<td nowrap='nowrap' align='left'>{$row['byte_size']}</td>";
			echo "<td nowrap='nowrap' align='left'>{$row['firstbytes']}</td>";
			echo "</tr>";
			
			
			
		}

		echo "</table><br />";
		$links = $paginator->getLinks ();
		echo "<div class='paginator'> " . $links ;

		echo "<p>Page " . $paginator->pageId . " of " . $paginator->totalPages . "</p>";

		?>
		</div> 
		</div>
		</div>			
			
			
			
			
			
			
			
 
	</body>
</html>